//使用express框架
const express = require("express");
//日志
const logger = require("morgan");
//图标
const favicon = require("serve-favicon");
const body_parser = require("body-parser");

//引入路由部分
const HXMRouter = require("./router/HXMRouter");
const LBRouter = require("./router/LBRouter");
const LCXRouter = require("./router/LCXRouter");
const YXXRouter = require("./router/YXXRouter");

let myExpress = express();

//配置日志
myExpress.use(logger("dev"));

//解决跨域问题
myExpress.all("*", (req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
  res.header(
    "Access-Control-Allow-Headers",
    "Content-Type,Content-Length, Authorization, Accept,X-Requested-With"
  );
  res.header("Access-Control-Allow-Credentials", "true");
  next();
});

//设置数据请求的body编码格式
myExpress.use(body_parser.urlencoded({ extended: false }));
myExpress.use(body_parser.json());

myExpress.use(HXMRouter);
myExpress.use(LBRouter);
myExpress.use(LCXRouter);
myExpress.use(YXXRouter);

//配置静态文件
myExpress.use(express.static(__dirname + "/dist"));
myExpress.use(favicon(__dirname + "/src/images/2.jpg"));

myExpress.listen(6789, function () {
  console.log("node_one,6789运行成功");
});
